package com.szxy.backend.item.service.impl;

import com.szxy.backend.item.feign.CommonItemsFeignClient;
import com.szxy.backend.item.service.ItemParamService;
import com.szxy.pojo.TbItemParam;
import com.szxy.utils.PageResult;
import com.szxy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther:zwer
 * @Date:2019/9/7 16:55
 * @Description:com.szxy.backend.item.service.impl
 * @Version:1.0
 **/
@Service
public class ItemParamServiceImpl implements ItemParamService {

    @Autowired
    private CommonItemsFeignClient commonItemsFeignClient;

    /**
     * 查询商品规格参数模板
     *
     * @param itemCatId 商品分类 ID
     * @return
     */
    @Override
    public Result selectItemParamByItemCatId(Long itemCatId) {
        TbItemParam tbItemParam = this.commonItemsFeignClient.selectItemParamByItemCatId(itemCatId);
        if (tbItemParam != null) {
            return Result.ok(tbItemParam);
        }
        return Result.error("查无数据");
    }

    @Override
    public Result selectItemParamAll(Integer page, Integer rows) {
        try {
            PageResult pageResult = this.commonItemsFeignClient.selectItemParamAll(page, rows);
            return Result.ok(pageResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("查询错误");
    }

    @Override
    public Result insertItemParam(TbItemParam itemParam) {
        int flag = this.commonItemsFeignClient.insertTbItemParam(itemParam);
        if (flag > 0) {
            return Result.ok();
        }
        return Result.error("插入错误");
    }

    @Override
    public Result deleteItemParamById(Long id) {
        int flag = this.commonItemsFeignClient.deleteItemParamById(id);
        if(flag >0 ){
            return Result.ok();
        }
        return Result.error("删除失败");
    }
}
